import { CMD } from "./BaseCMD";
import { GameMediator } from "./GameMediator";
import { puremvc } from "./puremvc";
import { Ctor, RegistPMVC } from "./RegistFunc";

//查询mediator和model
export class BaseFacade extends puremvc.Facade {
    get name() {
        return this.constructor.name;
    }
    static get Ins(): BaseFacade {
        return puremvc.Facade.getInstance(this.name);
    }
    static getMed<T extends GameMediator>(ctor: Ctor<T>) {
        if (!RegistPMVC.isExecuted)
            console.error("PMVC还未execute！");

        return puremvc.Facade.getInstance(this.Ins.name).retrieveMediator(ctor.name) as T;
    }
    static getCmd<T extends CMD<any>>(ctor: Ctor<T>) {
        if (!RegistPMVC.isExecuted)
            console.error("PMVC还未execute！");
        return puremvc.Facade.getInstance(this.Ins.name).retrieveCommand(ctor.name) as T;
    }
    static send<T, K extends CMD<T>>(cmd: Ctor<K>, param?: T) {
        puremvc.Facade.getInstance(this.Ins.name).sendNotification(cmd.name, param);

    }
}


